/* 
 * File:   Buffer.h
 * Author: root
 *
 * Created on October 27, 2015, 7:32 AM
 */

#ifndef BUFFER_H
#define	BUFFER_H

template<class T,int MaxSize>
class Buffer
{

    
public:
    T data[MaxSize];
    int bottom;
    int top;
    int cnt;
    Buffer();
    T* back();
    ~Buffer();
    T& operator[](int pos);
};

template<class T,int MaxSize>
Buffer<T,MaxSize>::Buffer()
{
    bottom = 0;
    top = 0;
    cnt = 0;
}

template<class T,int MaxSize>
T* Buffer<T,MaxSize>::back()
{
    return &this->data[(this->top + (MaxSize - 1)) % MaxSize];
}

template<class T,int MaxSize>
T& Buffer<T,MaxSize>::operator[](int pos)
{
    if (pos >= MaxSize || pos < 0)
    	return this->data[this->cnt % MaxSize];
}


template<class T,int MaxSize>
Buffer<T,MaxSize>::~Buffer()
{
}

#endif	/* BUFFER_H */

